﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Xejen.Communication.Soap
{
    /// <summary>
    /// 表示Wcf服务请求地址
    /// </summary>
    /// <creator>marc</creator>
    public class WcfAddress : SoapAddress
    {
        /// <summary>
        /// 服务接口的类型
        /// </summary>
        public Type ServiceType { get; set; }

        /// <inheritdoc cref="WcfAddress"/>
        public WcfAddress() { }

        /// <inheritdoc cref="WcfAddress"/>
        /// <param name="requestUri"><inheritdoc cref="SoapAddress.RequestUri" path="/summary"/></param>
        /// <param name="methodName"><inheritdoc cref="SoapAddress.MethodName" path="/summary"/></param>
        /// <param name="serviceType"><inheritdoc cref="ServiceType" path="/summary"/></param>
        public WcfAddress(string requestUri, string methodName, Type serviceType) : base(requestUri, methodName)
        {
            ServiceType = serviceType;
        }

        /// <inheritdoc/>
        public override string ToString()
        {
            return $"{nameof(RequestUri)}:{RequestUri}\r\n{nameof(MethodName)}:{MethodName}\r\n{nameof(ServiceType)}:{ServiceType}";
        }

        /// <inheritdoc/>
        public override int GetHashCode()
        {
            return (ServiceType, MethodName, ServiceType).GetHashCode();
        }

        /// <inheritdoc/>
        public override bool Equals(object obj)
        {
            var target = obj as WcfAddress;
            return ServiceType == target.ServiceType && MethodName == target.MethodName && RequestUri.ToLower() == target.RequestUri.ToLower();
        }
    }
}
